package com.itcodai.config.thread;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Before;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

//@Aspect
//@Component
public class ThreadPoolMonitorAspect {

    @Before("execution(* org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(..))")
    public void beforeExecute(JoinPoint joinPoint) {
        ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) joinPoint.getTarget();
        System.out.println("Active Threads: " + executor.getActiveCount());
    }

    @After("execution(* org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(..))")
    public void afterExecute(JoinPoint joinPoint) {
        ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) joinPoint.getTarget();
        System.out.println("Active Threads: " + executor.getActiveCount());
    }
}
